package com.anjue.data
{
	import flash.utils.Dictionary;
	
	/**
	 *HashMap类 
	 * @author anjue
	 * 
	 */
	public class HashMap
	{
		private var hash:Dictionary;
		private var keys:Array;
		public function HashMap()
		{
			hash = new Dictionary();
			keys = new Array();
		}
		
		/**
		 *往HashMap里新增一个值对 
		 * @param k 键
		 * @param v 值
		 * 
		 */
		public function putValue(k:Object,v:Object):void
		{
			if(!containsKey(k))
			{
				keys.push(k);
			}
			hash[k] = v;
		}
		
		public function delValue(k:Object):void
		{
			if(hash[k])
			{
				delete hash[k];
				var index:int = keys.indexOf(k);
				if(index>-1)
					keys.splice(index,1);
			}
		}
		
		/**
		 * @return 键值数组
		 */
		public function getKeys():Array
		{
			return keys;
		}
		
		/**
		 *获取键所对应的值 
		 * @param k 键
		 * @return 值
		 * 
		 */
		public function getValue(k:Object):Object
		{
			return hash[k];
		}
		
		/**
		 * 是否包含该键值
		 * @param k
		 * @return 
		 */
		private function containsKey(k:Object):Boolean
		{
			return hash[k] != null;
		}
	}
}